#!/usr/bin/env python
#coding:utf-8
import re,sys
import urllib,urllib2
from bs4 import BeautifulSoup

def get_info(name):
    so_url="http://movie.douban.com/subject_search?search_text="
    headers={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36'}
    data=urllib2.urlopen(so_url+name).read()
    r = re.findall(r'<a class="nbg" href=(.*?) onclick',data)
    r_url = re.sub('"','',r[0])
    url_data=urllib2.Request(r_url,headers=headers)
    get_data=urllib2.urlopen(url_data).read()
    soup = BeautifulSoup(get_data)
    print soup.find('title').get_text()
    print '豆瓣链接: %s' % r_url
    print soup.find(property='v:summary').get_text()
    jie= soup.find('div',id='info').get_text()
    print re.sub(u'IMDb链接:\s\S{0,17}','',jie)

if __name__=='__main__':
    name =str(raw_input("请输入电影名:"))
    get_info(name)
